﻿@model Citi.Scheduler.WebUi.Models.RoutineRequisiteModel
<script type="text/javascript">
    function updateAvailableMachines() {
        $('#tableAvailableMachines').html('<tr><th>Available Machines</th></tr>');

        $.ajax({
            url: '@Url.Action("SelectByRoutineConfigurations", "Machine")',
            type: "post",
            data: { routineId: $('#routineId').val() },
            success: function (json) {
                if (json.machines.length == 0) {
                    $('#tableAvailableMachines tr:last').after('<tr><td>No machines was found in this criteria.</td></tr>');
                }

                $.each(json.machines, function (index, item) {
                    $('#tableAvailableMachines tr:last').after('<tr><td>' + item + '</td></tr>');
                });
            }
        });
    }
</script>
@using (Ajax.BeginForm("AddConfiguration", new AjaxOptions { UpdateTargetId = "routineConfigurationList", OnSuccess = "updateAvailableMachines" }))
{
    @Html.Action("FormPartial", "Configuration")
    @Html.HiddenFor(model => model.RoutineId)
    <input type="submit" value="Add" />
}
<div id="routineConfigurationList">
    @Html.Action("Index", new { machineId = Model.RoutineId })
</div>
<input type="hidden" id="routineId" />
<br />
<div>
    <table id="tableAvailableMachines" class="table table-bordered table-striped" style="width: 90% !important;">
        <tr>
            <th>
                Available Machines
            </th>
        </tr>
    </table>
</div>
